package com.wnhz.work.yz.activity;

import android.content.Intent;
import android.content.res.Configuration;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.google.gson.Gson;
import com.umeng.socialize.ShareAction;
import com.umeng.socialize.UMShareAPI;
import com.umeng.socialize.UMShareListener;
import com.umeng.socialize.bean.SHARE_MEDIA;
import com.umeng.socialize.media.UMImage;
import com.umeng.socialize.media.UMWeb;
import com.umeng.socialize.shareboard.SnsPlatform;
import com.umeng.socialize.utils.ShareBoardlistener;
import com.wnhz.work.yz.BaseActivity;
import com.wnhz.work.yz.MyApplication;
import com.wnhz.work.yz.R;
import com.wnhz.work.yz.activity.webview.WebViewHomeActivity;
import com.wnhz.work.yz.bean.BathroomDetailBean;
import com.wnhz.work.yz.bean.Finish1;
import com.wnhz.work.yz.bean.VideoBean;
import com.wnhz.work.yz.fragment.bathroomdetails.InstallExplainFragment;
import com.wnhz.work.yz.fragment.bathroomdetails.ParameterFragment;
import com.wnhz.work.yz.fragment.bathroomdetails.ProbablyFragment;
import com.wnhz.work.yz.fragment.bathroomdetails.VideoFragment;
import com.wnhz.work.yz.utils.LogUtil;
import com.wnhz.work.yz.utils.Url;
import com.wnhz.work.yz.utils.xutils3.MyCallBack;
import com.wnhz.work.yz.utils.xutils3.XUtil;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * 作者： zxb
 * 日期： 2016/12/21
 * 描述： 浴室详情
 */
public class BathroomDetailActivity extends BaseActivity implements View.OnClickListener {
    private ProbablyFragment fragment1;
    private ParameterFragment fragment2;
    private VideoFragment fragment3;
    private InstallExplainFragment fragment4;

    private List<Fragment> fragmentList;
    private FragmentManager fragmentManager;
    private FragmentTransaction transaction;

    private TextView text1, text2, text3, text4;

    private int textColorNor, textColorCli;
    private View line1, line2, line3, line4;

    private TextView tv_collect;
    private ImageView bathroom_image1;
    private boolean isTrue;
    private LinearLayout ll;
    private String packageId;

    private BathroomDetailBean bean;

    private TextView tv_getTask, tv_buy, tv_xiadan;
    private List<BathroomDetailBean> beanList = new ArrayList<>();
    private List<VideoBean> videoBeanList = new ArrayList<>();
    private TextView btn_look_3d;
    private String d3_url;//3D链接

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_bathroom_detail);
        // MyApplication.getInstance().addDestoryActivity(this, "bathroom");
        EventBus.getDefault().register(this);
        initData();
        qqShare();
        initView();
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onEventMainThread(Finish1 event) {
        finish();
    }


    @Override
    protected void onDestroy() {
        EventBus.getDefault().unregister(this);//反注册EventBus
        super.onDestroy();
    }

    private void initData() {
        textColorNor = getResources().getColor(R.color.text_two);
        textColorCli = getResources().getColor(R.color.main_color);
        packageId = getIntent().getStringExtra("packageId");
        MyApplication.getInstance().jiji = packageId;
        Log.i(TAG, "initData: packageId= " + packageId);
    }

    private void initView() {
        bathroom_image1 = (ImageView) findViewById(R.id.bathroom_image1);
        tv_collect = (TextView) findViewById(R.id.tv_collect);

        tv_buy = (TextView) findViewById(R.id.tv_buy);
        tv_getTask = (TextView) findViewById(R.id.tv_getTask);
        tv_xiadan = (TextView) findViewById(R.id.tv_xiadan);
        ll = (LinearLayout) findViewById(R.id.ll);

        tv_getTask.setOnClickListener(this);
        tv_xiadan.setOnClickListener(this);
        tv_buy.setOnClickListener(this);

        findViewById(R.id.rl_fen).setOnClickListener(this);
        text1 = (TextView) findViewById(R.id.tv_probably);
        text2 = (TextView) findViewById(R.id.tv_parameter);
        text3 = (TextView) findViewById(R.id.tv_video);
        text4 = (TextView) findViewById(R.id.tv_install);

        line1 = findViewById(R.id.line1);
        line2 = findViewById(R.id.line2);
        line3 = findViewById(R.id.line3);
        line4 = findViewById(R.id.line4);

        text1.setOnClickListener(this);
        text2.setOnClickListener(this);
        text3.setOnClickListener(this);
        text4.setOnClickListener(this);

        fragmentList = new ArrayList<>();
        fragment1 = new ProbablyFragment();
        fragment2 = new ParameterFragment();
        fragment3 = new VideoFragment();
        fragment4 = new InstallExplainFragment();

        fragmentList.add(fragment1);
        fragmentList.add(fragment2);
        fragmentList.add(fragment3);
        fragmentList.add(fragment4);

        fragmentManager = getSupportFragmentManager();
        transaction = fragmentManager.beginTransaction();
        transaction.add(R.id.fl_bathRoom, fragment1);
        transaction.add(R.id.fl_bathRoom, fragment2);
        transaction.add(R.id.fl_bathRoom, fragment3);
        transaction.add(R.id.fl_bathRoom, fragment4);

        transaction.hide(fragment2);
        transaction.hide(fragment3);
        transaction.hide(fragment4);
        transaction.commit();

        btn_look_3d = (TextView) findViewById(R.id.btn_look_3d);
        btn_look_3d.setOnClickListener(this);
        upload();
    }

    private static final String TAG = "BathroomDetailActivity";

    private void upload() {
        showDialog();
        Map<String, Object> map = new HashMap<>();
        if (MyApplication.getInstance().getUserBean() == null) {
            map.put("token", "");
        } else {
            map.put("token", MyApplication.getInstance().getUserBean().getToken());
        }
        map.put("packageId", packageId);
        map.put("sign", "ztysxd");
        // MyToast(MyApplication.getInstance().getUserBean().getToken());
        XUtil.Post(Url.PACKAGE_GETPACKAGEDETAIL, map, new MyCallBack<String>() {
            @Override
            public void onSuccess(String result) {
                super.onSuccess(result);
                //   Log.i(TAG, "onSuccess: packageId==== " + result);
                LogUtil.e("-----", result);
                try {
                    JSONObject jsonObject = new JSONObject(result);
                    String res = jsonObject.optString("result");
                    if ("1".equals(res)) {
                        bean = new BathroomDetailBean();
                        Gson gson = new Gson();
                        JSONObject jsonObject1 = jsonObject.optJSONObject("info");
                        String collect_status = jsonObject1.optString("collect_status");

                        //Log.i("onSuccess: upload: ==", "--" + collect_status);
                        if ("0".equals(collect_status)) {
                        } else {
                            bathroom_image1.setImageResource(R.mipmap.ic_shangpinshoucang_li);
                            tv_collect.setText("已收藏");
                        }
                        bean = gson.fromJson(jsonObject.optString("info"), BathroomDetailBean.class);
                        beanList.add(bean);
                        fragment1.setBean(bean);

                        fragment4.setData(jsonObject1.optString("explain"));
                        Log.i(TAG, "onSuccess: packageId==== " + bean.getCan_buy());

                        if ("1".equals(bean.getCan_buy())) {
                            ll.setVisibility(View.GONE);
                            tv_xiadan.setVisibility(View.VISIBLE);
                        }else{
                            tv_xiadan.setVisibility(View.GONE);
                            ll.setVisibility(View.VISIBLE);
                        }

                        JSONArray j = jsonObject1.optJSONArray("video");
                        for (int i = 0; i < j.length(); i++) {
                            JSONObject j1 = j.getJSONObject(i);
                            VideoBean videoBean = gson.fromJson(j1.toString(), VideoBean.class);
                            videoBeanList.add(videoBean);
                        }
                        d3_url = jsonObject1.getString("d3_url");
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }

            }

            @Override
            public void onFinished() {
                super.onFinished();
                findViewById(R.id.iv_bathRoom_detail_back).setOnClickListener(BathroomDetailActivity.this);
                findViewById(R.id.rl_share).setOnClickListener(BathroomDetailActivity.this);
                findViewById(R.id.rl_cart).setOnClickListener(BathroomDetailActivity.this);
                findViewById(R.id.rl_bathroom_favor).setOnClickListener(BathroomDetailActivity.this);
                findViewById(R.id.rl_bathroom_service).setOnClickListener(BathroomDetailActivity.this);
                findViewById(R.id.tv_getTask).setOnClickListener(BathroomDetailActivity.this);

                fragment2.setBeanList(beanList);
                //  Toast.makeText(BathroomDetailActivity.this, "" + videoBeanList.size(), Toast.LENGTH_SHORT).show();
                fragment3.setData(videoBeanList);
                closeDialog();
            }

            @Override
            public void onError(Throwable ex, boolean isOnCallback) {
                closeDialog();
                super.onError(ex, isOnCallback);
            }
        });
    }

    private void hideFragment(int index) {
        FragmentTransaction transaction = fragmentManager.beginTransaction();
        for (int i = 0; i < fragmentList.size(); i++) {
            if (i == index) {
                transaction.show(fragmentList.get(i));
            } else {
                transaction.hide(fragmentList.get(i));
            }
        }
        transaction.commit();
    }


    @Override
    public void onClick(View v) {
        FragmentTransaction transaction = fragmentManager.beginTransaction();
        Intent intent;
        switch (v.getId()) {
            //返回
            case R.id.iv_bathRoom_detail_back:
                finish();
                break;

            //分享
            case R.id.rl_share:
                //  MyToast("分享");
                break;

            //添加购物车
            case R.id.rl_cart:
                // MyToast("添加购物车");
                /**
                 * entirety
                 entirety2
                 bathroom
                 */
//                MyApplication.getInstance().destoryActivity("entirety");
//                MyApplication.getInstance().destoryActivity("entirety2");
//                MyApplication.getInstance().destoryActivity("bathroom");
//                MyApplication.getInstance().destoryActivity("bathroomGrid");
//                MyApplication.getInstance().destoryActivity("search");
                EventBus.getDefault().post(new Finish1());

                EventBus.getDefault().post(new BathroomDetailBean());
                finish();
                break;

            //概括
            case R.id.tv_probably:
                hideFragment(0);
                transaction.show(fragmentList.get(0)).commit();
                text1.setTextColor(textColorCli);
                text2.setTextColor(textColorNor);
                text3.setTextColor(textColorNor);
                text4.setTextColor(textColorNor);

                line1.setVisibility(View.VISIBLE);
                line2.setVisibility(View.INVISIBLE);
                line3.setVisibility(View.INVISIBLE);
                line4.setVisibility(View.INVISIBLE);
                break;

            //参数
            case R.id.tv_parameter:
                hideFragment(1);
                transaction.show(fragmentList.get(1)).commit();
                text1.setTextColor(textColorNor);
                text2.setTextColor(textColorCli);
                text3.setTextColor(textColorNor);
                text4.setTextColor(textColorNor);

                line1.setVisibility(View.INVISIBLE);
                line2.setVisibility(View.VISIBLE);
                line3.setVisibility(View.INVISIBLE);
                line4.setVisibility(View.INVISIBLE);

                fragment2.scroll();
                break;

            //视频
            case R.id.tv_video:
                hideFragment(2);
                transaction.show(fragmentList.get(2)).commit();
                text1.setTextColor(textColorNor);
                text2.setTextColor(textColorNor);
                text3.setTextColor(textColorCli);
                text4.setTextColor(textColorNor);

                line1.setVisibility(View.INVISIBLE);
                line2.setVisibility(View.INVISIBLE);
                line3.setVisibility(View.VISIBLE);
                line4.setVisibility(View.INVISIBLE);
                break;

            //安装说明
            case R.id.tv_install:
                hideFragment(3);
                transaction.show(fragmentList.get(3)).commit();
                text1.setTextColor(textColorNor);
                text2.setTextColor(textColorNor);
                text3.setTextColor(textColorNor);
                text4.setTextColor(textColorCli);

                line1.setVisibility(View.INVISIBLE);
                line2.setVisibility(View.INVISIBLE);
                line3.setVisibility(View.INVISIBLE);
                line4.setVisibility(View.VISIBLE);
                break;

            //收藏
            case R.id.rl_bathroom_favor:
                //isTrue = !isTrue;
//                if (isTrue) {
//                    tv_collect.setText("已收藏");
//                    bathroom_image1.setImageResource(R.mipmap.ic_shangpinshoucang_li);
//
//                    isTrue = true;
//                } else {
//                    tv_collect.setText("收藏");
//                    bathroom_image1.setImageResource(R.mipmap.ic_shangpinshoucang_nor);
//                    isTrue = false;
//                }

                if (MyApplication.getInstance().getUserBean() == null) {
                    startActivity(new Intent(getApplicationContext(), LoginFirstActivity.class));
                    // finish();
                    return;
                }
                if ("已收藏".equals(tv_collect.getText())) {
                    cancleCollect();
                } else
                    collect();
                break;

            //客服
            case R.id.rl_bathroom_service:
//                MyToast("客服");
//                AlertDialog.Builder builder = new AlertDialog.Builder(this);
//                builder.setMessage("即将跳往拨打电话界面");
//
//                builder.setTitle("客服");
//
//                builder.setPositiveButton("确认", new DialogInterface.OnClickListener() {
//
//                    @Override
//                    public void onClick(DialogInterface dialog, int which) {
//
//                        Intent intent2 = new Intent(Intent.ACTION_DIAL);
//                        Uri data = Uri.parse("tel:" + "4006658880");
//                        intent2.setData(data);
//                        startActivity(intent2);
//                    }
//                });
//
//                builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
//
//                    @Override
//                    public void onClick(DialogInterface dialog, int which) {
//                        dialog.dismiss();
//                    }
//                });
//                builder.create().show();
                if (MyApplication.getInstance().getUserBean() == null) {
                    MyToast("请登录!");
                    Intent intent2 = new Intent(this, LoginNewActivity.class);
                    startActivity(intent2);
                    return;
                }
                intent = new Intent(this, YZServiceSelectActivity.class);
                startActivity(intent);
                break;
            //立即预约
            case R.id.tv_getTask:
                if (MyApplication.getInstance().getUserBean() != null) {
                    if (bean == null) {
                        return;
                    }

                    intent = new Intent(this, AppointMentMessageActivity.class);
                    intent.putExtra("bean", bean);
                    startActivity(intent);

                } else {
                    intent = new Intent(this, LoginFirstActivity.class);
                    startActivity(intent);
                }
                break;
            //核价下单
            case R.id.tv_xiadan:
                if (MyApplication.getInstance().getUserBean() != null) {
                    if (bean == null) {
                        return;
                    }

//                    startActivity(BathroomConditionActivity.createIntent(this, bean.getGoods_id(), "2"));
                    MyApplication.getInstance().setPricefale(1);
                    Intent intent3 = new Intent(this, SingleAllocationActivity.class);
                    intent3.putExtra("packageId", packageId);
                    intent3.putExtra("skuId", "");
                    intent3.putExtra("colorId", "");
                    intent3.putExtra("goods_id", packageId);
                    intent3.putExtra("goods_name",bean.getGoods_name());
                    startActivity(intent3);

                } else {
                    intent = new Intent(this, LoginFirstActivity.class);
                    startActivity(intent);
                }
                break;
            //立即购买
            case R.id.tv_buy:
                if (MyApplication.getInstance().getUserBean() != null) {
                    if (bean == null) {
                        return;
                    }
//                    startActivity(BathroomConditionActivity.createIntent(this, bean.getGoods_id(), "1"));
                    if (null != bean) {
                        Intent intent2 = new Intent(this, SingleAllocation2Activity.class);
                        intent2.putExtra("packageId", packageId);
                        intent2.putExtra("skuId", "");
                        intent2.putExtra("colorId", "");
                        intent2.putExtra("goods_name",bean.getGoods_name());

                        startActivity(intent2);
                    }
                } else {
                    intent = new Intent(this, LoginFirstActivity.class);
                    startActivity(intent);
                }
                break;
            case R.id.rl_fen:
                mShareAction.open();
                break;

            case R.id.btn_look_3d://查看3d效果
                Intent intent1 = new Intent(this,WebViewHomeActivity.class);
                intent1.putExtra("title","3D");
                intent1.putExtra("url",d3_url);
                startActivity(intent1);
                break;
            default:
                break;
        }

    }

    private void cancleCollect() {
        showDialog();
        Map<String, Object> map = new HashMap<>();
        try {
            map.put("token", MyApplication.getInstance().getUserBean().getToken());
        } catch (Exception e) {
            startActivity(new Intent(getApplicationContext(), LoginFirstActivity.class));
            return;
        }
        map.put("goodsId", packageId);
        map.put("type", "2");
        //   Log.i(TAG, "upload: == " + goodsId);
        XUtil.Post(Url.GOODS_CANCLECOLLECTGOODS, map, new MyCallBack<String>() {
            @Override
            public void onSuccess(String result) {
                closeDialog();
                JSONObject jsonObject = null;
                try {
                    jsonObject = new JSONObject(result);
                    String res = jsonObject.optString("result");
                    if ("1".equals(res)) {
                        bathroom_image1.setImageResource(R.mipmap.ic_shangpinshoucang_nor);
                        tv_collect.setText("收藏");
                    }
                    toast = jsonObject.optString("info");

                } catch (JSONException e) {
                    e.printStackTrace();
                }

                super.onSuccess(result);

            }

            @Override
            public void onFinished() {
                closeDialog();
                MyToast(toast);
                super.onFinished();
            }

            @Override
            public void onError(Throwable ex, boolean isOnCallback) {
                closeDialog();
                Log.i("---", "onError=" + ex);

                super.onError(ex, isOnCallback);
            }
        });
    }

    private String toast;

    private void collect() {
        showDialog();
        Map<String, Object> map = new HashMap<>();
        try {
            map.put("token", MyApplication.getInstance().getUserBean().getToken());
        } catch (Exception e) {
            startActivity(new Intent(getApplicationContext(), LoginFirstActivity.class));
            return;
        }
        map.put("goodsId", packageId);

        map.put("type", "2");
        //   Log.i(TAG, "upload: == " + goodsId);
        XUtil.Post(Url.GOODS_COLLECTGOODS, map, new MyCallBack<String>() {
            @Override
            public void onSuccess(String result) {
                closeDialog();
                JSONObject jsonObject = null;
                try {
                    jsonObject = new JSONObject(result);
                    String res = jsonObject.optString("result");
                    if ("1".equals(res)) {
                        bathroom_image1.setImageResource(R.mipmap.ic_shangpinshoucang_li);
                        tv_collect.setText("已收藏");
                    }

                    toast = jsonObject.optString("info");

                } catch (JSONException e) {
                    e.printStackTrace();
                }

                super.onSuccess(result);

            }

            @Override
            public void onFinished() {
                closeDialog();
                MyToast(toast);
                super.onFinished();
            }

            @Override
            public void onError(Throwable ex, boolean isOnCallback) {
                closeDialog();
                Log.i("---", "onError=" + ex);

                super.onError(ex, isOnCallback);
            }
        });
    }

    private ShareAction mShareAction;
    private UMShareListener mShareListener;

    private void qqShare() {
        mShareListener = new CustomShareListener(BathroomDetailActivity.this);
        /*增加自定义按钮的分享面板*/
        mShareAction = new ShareAction(BathroomDetailActivity.this).setDisplayList(//SHARE_MEDIA.WEIXIN_FAVORITE微信收藏
                SHARE_MEDIA.WEIXIN, SHARE_MEDIA.WEIXIN_CIRCLE, SHARE_MEDIA.QQ, SHARE_MEDIA.QZONE)
//                .addButton("umeng_sharebutton_copy", "umeng_sharebutton_copy", "umeng_socialize_copy", "umeng_socialize_copy")
//                .addButton("umeng_sharebutton_copyurl", "umeng_sharebutton_copyurl", "umeng_socialize_copyurl", "umeng_socialize_copyurl")
                .setShareboardclickCallback(new ShareBoardlistener() {
                    @Override
                    public void onclick(SnsPlatform snsPlatform, SHARE_MEDIA share_media) {
                        if (snsPlatform.mShowWord.equals("umeng_sharebutton_copy")) {
                            Toast.makeText(BathroomDetailActivity.this, "复制文本按钮", Toast.LENGTH_LONG).show();
                        } else if (snsPlatform.mShowWord.equals("umeng_sharebutton_copyurl")) {
                            Toast.makeText(BathroomDetailActivity.this, "复制链接按钮", Toast.LENGTH_LONG).show();

                        } else {
//                            UMWeb web = new UMWeb("http://blog.csdn.net/u011476017/article/details/12620725");
//                            web.setTitle("我的二维码");
//                            web.setDescription("来自优住的分享");
//                            web.setThumb(new UMImage(activity, R.drawable.mq_ic_file));
                            //  UMImage image = new UMImage(activity, imgu);//网络图片
                            if (bean == null) {
                                return;
                            }
                            MyApplication.getInstance().jiji = bean.getGoods_id();
                            UMWeb web = new UMWeb(bean.getShare_url());
                            web.setTitle(bean.getShare_title());
                            web.setDescription(bean.getShare_des());
                            web.setThumb(new UMImage(BathroomDetailActivity.this, bean.getShare_img()));


                            new ShareAction(BathroomDetailActivity.this).withMedia(web)
                                    .setPlatform(share_media)
                                    .setCallback(mShareListener)
                                    .share();
                        }
                    }
                });
    }

    private static class CustomShareListener implements UMShareListener {

        private WeakReference<BaseActivity> mActivity;

        private CustomShareListener(BathroomDetailActivity activity) {
            mActivity = new WeakReference(activity);
        }

        @Override
        public void onStart(SHARE_MEDIA platform) {

        }

        @Override
        public void onResult(SHARE_MEDIA platform) {

            if (platform.name().equals("WEIXIN_FAVORITE")) {
                Toast.makeText(mActivity.get(), platform + " 收藏成功啦", Toast.LENGTH_SHORT).show();
            } else {
                if (platform != SHARE_MEDIA.MORE && platform != SHARE_MEDIA.SMS
                        && platform != SHARE_MEDIA.EMAIL
                        && platform != SHARE_MEDIA.FLICKR
                        && platform != SHARE_MEDIA.FOURSQUARE
                        && platform != SHARE_MEDIA.TUMBLR
                        && platform != SHARE_MEDIA.POCKET
                        && platform != SHARE_MEDIA.PINTEREST
                        && platform != SHARE_MEDIA.INSTAGRAM
                        && platform != SHARE_MEDIA.GOOGLEPLUS
                        && platform != SHARE_MEDIA.YNOTE
                        && platform != SHARE_MEDIA.EVERNOTE) {
                    Log.e("----", "ffff");
                    upfen();
                    Toast.makeText(mActivity.get(), platform + " 分享成功啦", Toast.LENGTH_SHORT).show();
                }

            }
        }

        private void upfen() {
            Map<String, Object> map = new HashMap<>();
            map.put("type", 1);
            map.put("packageid", MyApplication.getInstance().jiji);
            Set keys = map.keySet();
            if (keys != null) {
                Iterator iterator = keys.iterator();
                while (iterator.hasNext()) {
                    Object key = iterator.next();
                    Object value = map.get(key);
                    Log.e("----" + key, "" + value + "\n");
                }
            }

            XUtil.Post(Url.API_SHARERETURN, map, new MyCallBack<String>() {
                @Override
                public void onSuccess(String result) {
                    super.onSuccess(result);
                    Log.i("----", "onSuccess:= " + result);

                }

                @Override
                public void onFinished() {
                    super.onFinished();
                }

                @Override
                public void onError(Throwable ex, boolean isOnCallback) {
                    super.onError(ex, isOnCallback);
                    ex.printStackTrace();
                }
            });


        }

        @Override
        public void onError(SHARE_MEDIA platform, Throwable t) {
            if (platform != SHARE_MEDIA.MORE && platform != SHARE_MEDIA.SMS
                    && platform != SHARE_MEDIA.EMAIL
                    && platform != SHARE_MEDIA.FLICKR
                    && platform != SHARE_MEDIA.FOURSQUARE
                    && platform != SHARE_MEDIA.TUMBLR
                    && platform != SHARE_MEDIA.POCKET
                    && platform != SHARE_MEDIA.PINTEREST
                    && platform != SHARE_MEDIA.INSTAGRAM
                    && platform != SHARE_MEDIA.GOOGLEPLUS
                    && platform != SHARE_MEDIA.YNOTE
                    && platform != SHARE_MEDIA.EVERNOTE) {
                Toast.makeText(mActivity.get(), platform + " 分享失败啦", Toast.LENGTH_SHORT).show();
                if (t != null) {
                    com.umeng.socialize.utils.Log.d("throw", "throw:" + t.getMessage());
                }
            }

        }

        @Override
        public void onCancel(SHARE_MEDIA platform) {

            Toast.makeText(mActivity.get(), platform + " 分享取消了", Toast.LENGTH_SHORT).show();
        }
    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        /** attention to this below ,must add this**/
        UMShareAPI.get(this).onActivityResult(requestCode, resultCode, data);
    }

    /**
     * 屏幕横竖屏切换时避免出现window leak的问题
     */
    @Override
    public void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);
        mShareAction.close();
    }
}
